import { useSystemStore } from '@/store/modules/system';
import { storeToRefs } from 'pinia';
import { omit } from 'lodash';
const systemStore = useSystemStore();
const { chartColor } = storeToRefs(systemStore);
export const pubGraphic = (data: any) => {
  return {
    type: 'text',
    left: 'center',
    top: 'middle',
    silent: true,
    invisible: data.length,
    style: {
      fill: chartColor,
      fontWeight: 'bold',
      text: '暂无数据',
      fontSize: '26px',
    },
  };
};
export const pubGrid = (legPos: string) => {
  const gridOptions = {
    left: '2%',
    right: '5%',
    bottom: '5%',
    top: '10%',
    containLabel: true,
  };
  return Object.assign(gridOptions, { [legPos]: '15%' });
};
export const pubXAxis = {
  type: 'category',
  nameLocation: 'end',
  nameTextStyle: {
    align: 'center',
    fontSize: 14,
    width: 10,
    overflow: 'break',
  },
  // nameRotate:90,
  axisLabel: {
    fontSize: 14,
  },
  axisTick: {
    show: false,
  },
  axisLine: {
    show: true,
    lineStyle: {
      color: chartColor,
    },
  },
};
export const pubYAxis = {
  type: 'value',
  nameLocation: 'end',
  nameTextStyle: {
    align: 'center',
    fontSize: 14,
    color: chartColor,
  },
  max: function () {
    return undefined;
  },
  min: function () {
    return undefined;
  },
  // nameGap: 40,
  axisLabel: {
    fontSize: 14,
  },
  splitLine: {
    show: true,
    lineStyle: {
      color: '#ccc',
    },
  },
  axisLine: {
    show: false,
    lineStyle: {
      color: chartColor,
    },
  },
  animationDurationUpdate: 300,
  animationDuration: 300,
};
export const pubLegend = (legend: any) => {
  const legendOptions = {
    type: 'scroll',
    width: '100%',
    top: 'bottom',
    textStyle: {
      fontSize: 14,
      color: chartColor,
    },
  };
  switch (legend.position) {
    case 'top':
      Object.assign(legendOptions, { top: 5 });
      break;
    case 'left':
      Object.assign(legendOptions, { left: 5, top: 'middle' });
      break;
    case 'right':
      Object.assign(legendOptions, { right: 5, top: 'middle' });
      break;

    default:
      Object.assign(legendOptions, { top: 'bottom' });
      break;
  }
  return Object.assign(legendOptions, omit(legend, ['position']));
};
export const pubLabel = {
  position: 'top',
  fontSize: 14,
  color: chartColor,
};
export const pubDataZoom = {
  show: false,
};
export const pubBackground = (bgColor?: string) => {
  return bgColor ? bgColor : 'transparent';
};
